package cn.com.zsw.gblog.exception;

/**
 * @Author ：shiwangzhou
 * @Date ：Created in 2020-07-08 16:20
 * @Description： 全局异常捕获
 */

import cn.com.zsw.gblog.vo.R;
import io.jsonwebtoken.ExpiredJwtException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局统一异常处理
 *
 * @Author zsw
 * @Date 2019-08-06
 * @Parameter * @param null
 * @Version 1.0.0
 * @Return
 */

//@RestControllerAdvice(basePackages = "cn.com.zsw.gblog")
@Slf4j
public class GlobalException {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public R errorResult(HttpServletRequest req, RuntimeException e) {
        String errorMsg = e.getMessage();
        log.error("请求地址：[{}] 运行时异常 {}", req.getRequestURI(), errorMsg);
        return R.status(500).msg(e.getMessage());
    }
    @ExceptionHandler(ExpiredJwtException.class)
    @ResponseBody
    public R expiredJwtException(HttpServletRequest req, RuntimeException e) {
        log.error("token已经过期");
        return R.status(5003).msg("token已经过期");
    }

}
